# Copyright 2009-2012 The Go Authors. All rights reserved.
# Use of this source code is governed by a BSD-style
# license that can be found in the LICENSE file.

all: scanner.go parser.go xerror.go
	go install

scanner.go: scanner.l
	golex -t $< | gofmt > $@

parser.go: parser.y
	go tool yacc -l -o $@ $<
	sed -i 's|//line.*||; s/^func yyParse(yylex yyLexer) int {/func yyParse(yylex *lexer) int {/; s/yylex.Error("syntax error")/yylex.xError(yyS, yyp)/' $@
	gofmt -w $@

xerror.go: parser.go xerrors/xerror_defs.go
	cp xerror $@
	make -C xerrors/ clean all
	./xerrors/xerrors >> $@

clean:
	rm -f lex.yy.go yacc.tab y.output y.tab.c scanner.go parser.go y.go *~
